import { _decorator, Component, EditBox, Node } from 'cc';
import ViewBase from '../../../../src/engine/ViewBase';
import { UI_Cache_Type, UI_Config } from '../../../../src/engine/UI_Config';
import { BundleConfig } from '../../../../src/config/BundleConfig';
import { AccountModel } from '../model/AccountModel';
import { EventManager } from '../../../../src/engine/EventManager';
import { UIManager } from '../../../../src/engine/UIManager';
import { ViewTip } from '../../../../src/view/ViewTip';
import { HttpController } from '../../../../src/controller/HttpController';
import { HallHttpController } from '../../controller/HallHttpController';
import { ViewRegister } from './ViewRegister';
const { ccclass, property } = _decorator;


@ccclass('login/ViewAccount')
export class ViewAccount extends ViewBase {

    //ui 配置 
    public static uiConfig: UI_Config = new UI_Config("res/login/prefab/ViewAccount",
        UI_Cache_Type.noCache, true, BundleConfig.hall);


    private txtAccount: EditBox;
    private txtPass: EditBox;
    private btnRegister: Node;
    private btnLogin: Node;

    protected onShow(): void {
        AccountModel.instance.init()

        // AccountModel.instance.account = "o9glZ6Bv6E_Zm4-ICttddrSoarhE"
        // AccountModel.instance.password = "123456"
        this.txtAccount = this.getChild(this.contentNode, "txtAccount", EditBox);
        this.txtAccount.string = AccountModel.instance.account
        this.txtPass = this.getChild(this.contentNode, "txtPass", EditBox);
        this.txtPass.string = AccountModel.instance.password
        this.btnRegister = this.findChild(this.contentNode, "btnRegister")
        EventManager.onAddEvent(this.btnRegister, () => {
            UIManager.instance.showView(ViewRegister.uiConfig);
        })
        this.btnLogin = this.findChild(this.contentNode, "btnLogin")
        EventManager.onAddEvent(this.btnLogin, () => {
            if (this.txtAccount.string == "" || this.txtPass.string == "") {
                UIManager.instance.showTip("请输入账号密码", ViewTip.TipType.Fail);
                return
            }
            HallHttpController.account_auth(this.txtAccount.string, this.txtPass.string);
        })
    }

    protected onHide(callfunc?: Function): void {

    }
}

